/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quizzempire.view;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import quizzempire.model.IModel;
import quizzempire.model.IQuestion;
import quizzempire.model.IQuizz;
import quizzempire.model.statemachine.State;

/**
 *
 * @author Victor
 */
public class QuestionEditor extends javax.swing.JFrame implements Observer {

    /**
     * Creates new form QuestionEditor
     */
    
    IModel model;
    IQuizz quizz;
    ArrayList<IQuestion> questions;
    
    public QuestionEditor(IModel model) {
        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
        this.model = model;
        quizz = model.getQuizzViewer();
        questions = quizz.getQuestionsViewer();
        //initFields();
        model.addObserver(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rbEasy = new javax.swing.JRadioButton();
        rbMedium = new javax.swing.JRadioButton();
        rbHard = new javax.swing.JRadioButton();
        lbLogo = new javax.swing.JLabel();
        lbDifficulty = new javax.swing.JLabel();
        cbEasy = new javax.swing.JCheckBox();
        cbMedium = new javax.swing.JCheckBox();
        cbHard = new javax.swing.JCheckBox();
        listQuestions = new javax.swing.JScrollPane();
        QuestionList = new javax.swing.JList();
        btMainMenu = new javax.swing.JButton();
        btPreviousStep = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();
        rbAnswerA = new javax.swing.JRadioButton();
        rbAnswerB = new javax.swing.JRadioButton();
        rbAnswerC = new javax.swing.JRadioButton();
        rbAnswerD = new javax.swing.JRadioButton();
        tbNewQuestion = new javax.swing.JTextField();
        btNewQuestion = new javax.swing.JButton();
        lbCounterEasy = new javax.swing.JLabel();
        lbCounterMedium = new javax.swing.JLabel();
        lbCounterHard = new javax.swing.JLabel();
        lbQuestion = new javax.swing.JLabel();
        textQuestion = new javax.swing.JScrollPane();
        taQuestion = new javax.swing.JTextArea();
        lbAnswers = new javax.swing.JLabel();
        textAnswerA = new javax.swing.JTextField();
        textAnswerC = new javax.swing.JTextField();
        textAnswerB = new javax.swing.JTextField();
        textAnswerD = new javax.swing.JTextField();
        lbFilter = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        rbEasy.setText("Easy");
        rbEasy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbEasyActionPerformed(evt);
            }
        });

        rbMedium.setText("Medium");

        rbHard.setText("Hard");

        lbLogo.setText("LOGO");

        lbDifficulty.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lbDifficulty.setText("Difficulty");

        cbEasy.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
        cbEasy.setText("Easy");

        cbMedium.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
        cbMedium.setText("Medium");

        cbHard.setFont(new java.awt.Font("Dialog", 0, 10)); // NOI18N
        cbHard.setText("Hard");

        QuestionList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        listQuestions.setViewportView(QuestionList);

        btMainMenu.setText("MAIN MENU");
        btMainMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMainMenuActionPerformed(evt);
            }
        });

        btPreviousStep.setText("PREVIOUS STEP");

        buttonSave.setText("SAVE QUIZZ");

        rbAnswerA.setText("a)");
        rbAnswerA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbAnswerAActionPerformed(evt);
            }
        });

        rbAnswerB.setText("b)");

        rbAnswerC.setText("c)");

        rbAnswerD.setText("d)");

        tbNewQuestion.setText("jTextField2");

        btNewQuestion.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
        btNewQuestion.setText("NEW");

        lbCounterEasy.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
        lbCounterEasy.setText("10/10");

        lbCounterMedium.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
        lbCounterMedium.setText("5/10");

        lbCounterHard.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
        lbCounterHard.setText("10/30");

        lbQuestion.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lbQuestion.setText("Question");

        taQuestion.setColumns(20);
        taQuestion.setRows(5);
        textQuestion.setViewportView(taQuestion);

        lbAnswers.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lbAnswers.setText("Answers");

        textAnswerA.setText("jTextField1");

        textAnswerC.setText("jTextField3");
        textAnswerC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textAnswerCActionPerformed(evt);
            }
        });

        textAnswerB.setText("jTextField4");

        textAnswerD.setText("jTextField5");

        lbFilter.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lbFilter.setText("Filter");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbFilter)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbEasy, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbMedium)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbHard))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(tbNewQuestion)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(btNewQuestion))
                                .addComponent(listQuestions, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbDifficulty)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(rbEasy)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(12, 12, 12)
                                                .addComponent(lbCounterEasy)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(rbMedium)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                .addComponent(lbCounterMedium)
                                                .addGap(26, 26, 26)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(rbHard)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(13, 13, 13)
                                                .addComponent(lbCounterHard))))
                                    .addComponent(lbQuestion)
                                    .addComponent(lbAnswers)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(rbAnswerC)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(textAnswerC))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(rbAnswerA)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(textAnswerA, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(rbAnswerD, javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(rbAnswerB, javax.swing.GroupLayout.Alignment.TRAILING))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textAnswerB, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                                    .addComponent(textAnswerD)))
                            .addComponent(textQuestion)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btMainMenu)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btPreviousStep)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbDifficulty)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbCounterEasy)
                            .addComponent(lbCounterMedium)
                            .addComponent(lbCounterHard))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rbEasy)
                            .addComponent(rbMedium)
                            .addComponent(rbHard)))
                    .addComponent(lbLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbQuestion)
                    .addComponent(lbFilter))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbAnswers)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rbAnswerA)
                            .addComponent(rbAnswerB)
                            .addComponent(textAnswerA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textAnswerB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rbAnswerC)
                            .addComponent(rbAnswerD)
                            .addComponent(textAnswerC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textAnswerD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbEasy)
                            .addComponent(cbMedium)
                            .addComponent(cbHard))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(listQuestions, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tbNewQuestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btNewQuestion))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btMainMenu)
                    .addComponent(btPreviousStep)
                    .addComponent(buttonSave))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rbEasyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbEasyActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbEasyActionPerformed

    private void rbAnswerAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbAnswerAActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbAnswerAActionPerformed

    private void textAnswerCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textAnswerCActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textAnswerCActionPerformed

    private void btMainMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMainMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btMainMenuActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList QuestionList;
    private javax.swing.JButton btMainMenu;
    private javax.swing.JButton btNewQuestion;
    private javax.swing.JButton btPreviousStep;
    private javax.swing.JButton buttonSave;
    private javax.swing.JCheckBox cbEasy;
    private javax.swing.JCheckBox cbHard;
    private javax.swing.JCheckBox cbMedium;
    private javax.swing.JLabel lbAnswers;
    private javax.swing.JLabel lbCounterEasy;
    private javax.swing.JLabel lbCounterHard;
    private javax.swing.JLabel lbCounterMedium;
    private javax.swing.JLabel lbDifficulty;
    private javax.swing.JLabel lbFilter;
    private javax.swing.JLabel lbLogo;
    private javax.swing.JLabel lbQuestion;
    private javax.swing.JScrollPane listQuestions;
    private javax.swing.JRadioButton rbAnswerA;
    private javax.swing.JRadioButton rbAnswerB;
    private javax.swing.JRadioButton rbAnswerC;
    private javax.swing.JRadioButton rbAnswerD;
    private javax.swing.JRadioButton rbEasy;
    private javax.swing.JRadioButton rbHard;
    private javax.swing.JRadioButton rbMedium;
    private javax.swing.JTextArea taQuestion;
    private javax.swing.JTextField tbNewQuestion;
    private javax.swing.JTextField textAnswerA;
    private javax.swing.JTextField textAnswerB;
    private javax.swing.JTextField textAnswerC;
    private javax.swing.JTextField textAnswerD;
    private javax.swing.JScrollPane textQuestion;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o, Object arg) {
        State state = model.getState(); 
        if (!(state instanceof quizzempire.model.statemachine.QuestionEditor))
            MainBuilder.changeScreen(this, model, state);
    }
}
